#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>

struct listnode
{
	int val;
	struct listnode* next;
};

struct listnode* reverselist(struct listnode* head)
{
	struct listnode* prev = NULL;
	struct listnode* cur = head;
	struct listnode* next = NULL;

	while (cur)
	{
		next = cur->next;
		cur->next = prev;
		prev = cur;
		cur = next;
	}

	return prev;
}
void printlistnode(struct listnode* head)
{
	while (head)
	{
		printf("%d ", head->val);
		head = head->next;
	}
}

struct listnode* creatnode(int n)
{
	struct listnode* newnode = (struct listnode*)malloc(sizeof(struct listnode));
	newnode->val = n;
	newnode->next = NULL;
	return newnode;
}

int main()
{
	struct listnode* List = creatnode(1);
	List->next = creatnode(2);
	List->next->next = creatnode(3);
	List->next->next->next = creatnode(4);

	printlistnode(List);
	printf("\n");

	struct listnode* newlist = reverselist(List);

	printlistnode(newlist);

	return 0;
}